package com.kexio.log.analytics.service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 日志分析服务接口
 * 
 * 提供日志分析、统计和报告功能
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public interface LogAnalyticsService {
    
    /**
     * 获取错误统计信息
     * 
     * @return 错误统计数据
     */
    ErrorStatistics getErrorStatistics();
    
    /**
     * 获取性能统计信息
     * 
     * @return 性能统计数据
     */
    PerformanceStatistics getPerformanceStatistics();
    
    /**
     * 获取用户行为分析
     * 
     * @param timeRange 时间范围
     * @return 用户行为分析结果
     */
    UserBehaviorAnalysis getUserBehaviorAnalysis(String timeRange);
    
    /**
     * 生成分析报告
     * 
     * @param reportType 报告类型
     * @param format 格式
     * @return 报告内容
     */
    String generateReport(String reportType, String format);
    
    /**
     * 重置分析数据
     */
    void resetAnalytics();
    
    /**
     * 错误统计
     */
    class ErrorStatistics {
        private long totalErrors;
        private double errorRate;
        private Map<String, Long> errorTypes;
        private List<String> topErrors;
        private LocalDateTime timestamp;
        
        public ErrorStatistics(long totalErrors, double errorRate, Map<String, Long> errorTypes,
                              List<String> topErrors, LocalDateTime timestamp) {
            this.totalErrors = totalErrors;
            this.errorRate = errorRate;
            this.errorTypes = errorTypes;
            this.topErrors = topErrors;
            this.timestamp = timestamp;
        }
        
        // Getters and Setters
        public long getTotalErrors() { return totalErrors; }
        public void setTotalErrors(long totalErrors) { this.totalErrors = totalErrors; }
        
        public double getErrorRate() { return errorRate; }
        public void setErrorRate(double errorRate) { this.errorRate = errorRate; }
        
        public Map<String, Long> getErrorTypes() { return errorTypes; }
        public void setErrorTypes(Map<String, Long> errorTypes) { this.errorTypes = errorTypes; }
        
        public List<String> getTopErrors() { return topErrors; }
        public void setTopErrors(List<String> topErrors) { this.topErrors = topErrors; }
        
        public LocalDateTime getTimestamp() { return timestamp; }
        public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; }
    }
    
    /**
     * 性能统计
     */
    class PerformanceStatistics {
        private double averageResponseTime;
        private long slowRequests;
        private double slowRequestRate;
        private Map<String, Double> endpointPerformance;
        private LocalDateTime timestamp;
        
        public PerformanceStatistics(double averageResponseTime, long slowRequests, double slowRequestRate,
                                   Map<String, Double> endpointPerformance, LocalDateTime timestamp) {
            this.averageResponseTime = averageResponseTime;
            this.slowRequests = slowRequests;
            this.slowRequestRate = slowRequestRate;
            this.endpointPerformance = endpointPerformance;
            this.timestamp = timestamp;
        }
        
        // Getters and Setters
        public double getAverageResponseTime() { return averageResponseTime; }
        public void setAverageResponseTime(double averageResponseTime) { this.averageResponseTime = averageResponseTime; }
        
        public long getSlowRequests() { return slowRequests; }
        public void setSlowRequests(long slowRequests) { this.slowRequests = slowRequests; }
        
        public double getSlowRequestRate() { return slowRequestRate; }
        public void setSlowRequestRate(double slowRequestRate) { this.slowRequestRate = slowRequestRate; }
        
        public Map<String, Double> getEndpointPerformance() { return endpointPerformance; }
        public void setEndpointPerformance(Map<String, Double> endpointPerformance) { this.endpointPerformance = endpointPerformance; }
        
        public LocalDateTime getTimestamp() { return timestamp; }
        public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; }
    }
    
    /**
     * 用户行为分析
     */
    class UserBehaviorAnalysis {
        private long activeUsers;
        private Map<String, Long> topActions;
        private Map<String, Long> topResources;
        private List<String> userPatterns;
        private LocalDateTime timestamp;
        
        public UserBehaviorAnalysis(long activeUsers, Map<String, Long> topActions, Map<String, Long> topResources,
                                   List<String> userPatterns, LocalDateTime timestamp) {
            this.activeUsers = activeUsers;
            this.topActions = topActions;
            this.topResources = topResources;
            this.userPatterns = userPatterns;
            this.timestamp = timestamp;
        }
        
        // Getters and Setters
        public long getActiveUsers() { return activeUsers; }
        public void setActiveUsers(long activeUsers) { this.activeUsers = activeUsers; }
        
        public Map<String, Long> getTopActions() { return topActions; }
        public void setTopActions(Map<String, Long> topActions) { this.topActions = topActions; }
        
        public Map<String, Long> getTopResources() { return topResources; }
        public void setTopResources(Map<String, Long> topResources) { this.topResources = topResources; }
        
        public List<String> getUserPatterns() { return userPatterns; }
        public void setUserPatterns(List<String> userPatterns) { this.userPatterns = userPatterns; }
        
        public LocalDateTime getTimestamp() { return timestamp; }
        public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; }
    }
}
